package servlet;

import util.Linksql;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TeaChangeServlet extends HttpServlet {
    String sqlone="select * from teacher where teacherid="+"?";
    ResultSet resultSet=null;
    PreparedStatement pre=null;
    Connection conn=null;
    String id=null;
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            id=request.getParameter("id");
            conn= Linksql.getConnection();
            pre=conn.prepareStatement(sqlone);
            pre.setString(1, id);
            resultSet=pre.executeQuery();
            while (resultSet.next()){
                request.setAttribute("teacherid",resultSet.getString("teacherid"));
                request.setAttribute("password",resultSet.getString("password"));
                request.setAttribute("name",resultSet.getString("name"));
                request.setAttribute("department",resultSet.getString("department"));
                request.setAttribute("title",resultSet.getString("title"));
                request.setAttribute("phone",resultSet.getString("phone"));
                request.setAttribute("email",resultSet.getString("email"));
                request.setAttribute("credit score",resultSet.getInt("credit score"));
            }
            request.getRequestDispatcher("TeaChange.jsp").forward(request,response);
            resultSet.close();
            pre.close();
            conn.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    }
